package com.rasenhund.android.grecorder.common;

import java.util.ArrayList;

import android.content.Context;
import android.os.Environment;

import com.rasenhund.android.grecorder.R;
import com.rasenhund.android.grecorder.schema.StageRecord;


public class Const {
    // @SuppressWarnings("unused")
    // private static final String TAG = Const.class.getSimpleName();
    // private final Const self = this;
    
    private static final String CSV_FILE_NAME = "data.csv";
    private static final int DATABASE_VERSION = 3;

    /**
     * パラメータ受け渡し用のキー
     */
    public class KEY {
        // public static final String KEY_RECORD = "KEY_RECORD";
        public static final String KEY_STAGE = "KEY_STAGE";
        public static final String KEY_ROWID = "KEY_ROWID";
        // public static final String KEY_RECORD_ITEM = "KEY_RECORD_ITEM";
        public static final String KEY_STAGE1 = "KEY_STAGE1";
        public static final String KEY_STAGE2 = "KEY_STAGE2";
        public static final String KEY_LAST_DATE = "KEY_LAST_DATE";
    }

    public static final String PREFERENCE_NAME = "pref";
    /**
     * Preference領域格納用キー
     */
    public class PrefKey {
        public static final String PREF_KEY_ARMY_CODE = "PREF_KEY_ARMY_CODE";
    }

    /**
     * ステージコード
     */
    public class STAGE{
        
        // 全件取得用
        public static final int ALL = 999; // 全ステージ

        // 地上ステージ
        public static final int NEW_YARK = 0; // ニューヤーク
        public static final int NEW_YARK_R = 1; // ニューヤーク(R)
        public static final int NEW_YARK_NIGHT = 2; // ニューヤーク(夜)
        public static final int NEW_YARK_NIGHT_R = 3; // ニューヤーク(夜)(R)
        public static final int JABRO_GROUND = 4; // ジャブロー地上
        public static final int HIMALAYAS = 5; // ヒマラヤ
        public static final int HIMALAYAS_R = 6; // ヒマラヤ(R)
        public static final int MINING_TOWN = 7; // 鉱山都市
        public static final int MINING_TOWN_R = 8; // 鉱山都市(R)
        public static final int MINING_TOWN_NIGHT = 9; // 鉱山都市(夜)
        public static final int MINING_TOWN_R_NIGHT = 10; // 鉱山都市(夜)(R)
        public static final int THE_ARCTIC_BASE = 11; // 北極基地
        public static final int ODESSA = 12; // オデッサ
        public static final int ODESSA_R = 13; // オデッサ(R)
        public static final int AUSTRARIA = 14; // オーストラリア演習場 // *
        public static final int BERUFAST = 15; // ベルファスト // *
        public static final int TAKLAMAKAN_DESERT = 16; // タクラマカン砂漠
        public static final int JABRO = 17; // ジャブロー地下
        public static final int TORRINGTON = 18; // トリントン
        public static final int TORRINGTON_R = 19; // トリントン(R)
        public static final int GREAT_CANYON = 20; // グレートキャニオン
        public static final int TORRINGTON_BASE = 21; // トリントン基地
        public static final int CALIFORNIA_BASE = 22; // キャリフォルニア・ベース

        // 宇宙ステージ
        public static final int A_BAOA_QU = 23; // ア・バオア・クー
        public static final int A_BAOA_QU_R = 24; // ア・バオア・クー(R)
        public static final int LUNA_II = 25; // ルナツー
        public static final int ISRAND_EASE = 26; // アイランド・イーズ
        
        // コロニー
        public static final int SIDE_7 = 27; // サイド7 // *
        public static final int RIBO_COLONY = 28; // リボー・コロニー
        public static final int RIBO_COLONY_AREA_B = 29; // リボー・コロニー_エリアB
        
        public static final int JABURO_JUNGLE_AREA = 30; // ジャブロー地上密林エリア
        public static final int GRANADA = 31; // グラナダ

    }

    /**
     * 軍コード
     */
    public class ARMY {

        public static final int NONE = 0; // 未所属
        public static final int EFSF = 1; // 地球連邦軍
        public static final int POZ = 2; // ジオン公国軍

    }

    /**
     * カテゴリコード
     */
    public class CATEGORY{
        
        public static final int GRAPP = 0;
        public static final int PROX = 1;
        public static final int SHOOT = 2;
        public static final int CANNON = 3;
        public static final int SNIPE = 4;

    }
    
    /**
     * 結果コード
     */
    public class RESULT{
        
        public static final int WIN = 0;
        public static final int LOSE = 1;
        public static final int DRAW = 2;
        public static final int PERFECT_WIN = 3;
        public static final int PERFECT_LOSE = 4;
        
    }
    
    /**
     * ステージ一覧の取得
     * 
     * @param context
     * @return
     */
    public static ArrayList<StageRecord> getStageList(Context context){
        
        ArrayList<StageRecord> list = new ArrayList<StageRecord>();        
        
        // @formatter:off
        list.add(new StageRecord(STAGE.NEW_YARK, context.getResources().getString(R.string.stage_new_yark)));
        list.add(new StageRecord(STAGE.NEW_YARK_R, context.getResources().getString(R.string.stage_new_yark_r)));
        list.add(new StageRecord(STAGE.NEW_YARK_NIGHT, context.getResources().getString(R.string.stage_new_yark_night)));
        list.add(new StageRecord(STAGE.NEW_YARK_NIGHT_R, context.getResources().getString(R.string.stage_new_yark_night_r)));
        list.add(new StageRecord(STAGE.JABRO_GROUND, context.getResources().getString(R.string.stage_jaburo_ground)));
        list.add(new StageRecord(STAGE.HIMALAYAS, context.getResources().getString(R.string.stage_himalayas)));
        list.add(new StageRecord(STAGE.HIMALAYAS_R, context.getResources().getString(R.string.stage_himalayas_r)));
        list.add(new StageRecord(STAGE.MINING_TOWN, context.getResources().getString(R.string.stage_mining_town)));
        list.add(new StageRecord(STAGE.MINING_TOWN_R, context.getResources().getString(R.string.stage_mining_town_r)));
        list.add(new StageRecord(STAGE.MINING_TOWN_NIGHT, context.getResources().getString(R.string.stage_mining_town_night)));
        list.add(new StageRecord(STAGE.MINING_TOWN_R_NIGHT, context.getResources().getString(R.string.stage_mining_town_night_r)));
        list.add(new StageRecord(STAGE.THE_ARCTIC_BASE, context.getResources().getString(R.string.stage_the_arctic_base)));
        list.add(new StageRecord(STAGE.ODESSA, context.getResources().getString(R.string.stage_odessa)));
        list.add(new StageRecord(STAGE.ODESSA_R, context.getResources().getString(R.string.stage_odessa_r)));
        list.add(new StageRecord(STAGE.AUSTRARIA, context.getResources().getString(R.string.stage_austraria)));
        list.add(new StageRecord(STAGE.BERUFAST, context.getResources().getString(R.string.stage_berufast)));
        list.add(new StageRecord(STAGE.TAKLAMAKAN_DESERT, context.getResources().getString(R.string.stage_taklamakan_desert)));
        list.add(new StageRecord(STAGE.JABRO, context.getResources().getString(R.string.stage_jaburo)));
        list.add(new StageRecord(STAGE.TORRINGTON, context.getResources().getString(R.string.stage_torrington)));
        list.add(new StageRecord(STAGE.TORRINGTON_R, context.getResources().getString(R.string.stage_torrington_r)));
        list.add(new StageRecord(STAGE.GREAT_CANYON, context.getResources().getString(R.string.stage_great_canyon)));
        list.add(new StageRecord(STAGE.TORRINGTON_BASE, context.getResources().getString(R.string.stage_torrington_base)));
        list.add(new StageRecord(STAGE.CALIFORNIA_BASE, context.getResources().getString(R.string.stage_california_base)));
        list.add(new StageRecord(STAGE.A_BAOA_QU, context.getResources().getString(R.string.stage_a_baoa_qu)));
        list.add(new StageRecord(STAGE.A_BAOA_QU_R, context.getResources().getString(R.string.stage_a_baoa_qu_r)));
        list.add(new StageRecord(STAGE.LUNA_II, context.getResources().getString(R.string.stage_luna_two)));
        list.add(new StageRecord(STAGE.ISRAND_EASE, context.getResources().getString(R.string.stage_island_ease)));
        list.add(new StageRecord(STAGE.SIDE_7, context.getResources().getString(R.string.stage_side_7)));
        list.add(new StageRecord(STAGE.RIBO_COLONY, context.getResources().getString(R.string.stage_ribo_colony)));
        list.add(new StageRecord(STAGE.RIBO_COLONY_AREA_B, context.getResources().getString(R.string.stage_ribo_colony_area_b)));
        list.add(new StageRecord(STAGE.JABURO_JUNGLE_AREA, context.getResources().getString(R.string.stage_jaburo_jungle_area)));
        list.add(new StageRecord(STAGE.GRANADA, context.getResources().getString(R.string.stage_granada)));
        // @formatter:on
        
        return list;
    }

    /**
     * 所属軍名の取得
     * 
     * @param context
     * @param armyCd
     * @return
     */
    public static String getArmyNm(Context context, int armyCd) {

        switch (armyCd) {
            case ARMY.EFSF:
                return context.getResources().getString(R.string.army_efsf);

            case ARMY.POZ:
                return context.getResources().getString(R.string.army_poz);

            default:
                return context.getResources().getString(R.string.army_empty);

        }

    }

    /**
     * ステージ名の取得
     * 
     * @param context
     * @param stageId
     * @return
     */
    public static String getStageNm(Context context, int stageId) {

        switch (stageId) {
            case STAGE.ALL:
                return context.getResources().getString(R.string.stage_all);

            case STAGE.NEW_YARK:
                return context.getResources().getString(R.string.stage_new_yark);

            case STAGE.NEW_YARK_R:
                return context.getResources().getString(R.string.stage_new_yark_r);

            case STAGE.NEW_YARK_NIGHT:
                return context.getResources().getString(R.string.stage_new_yark_night);

            case STAGE.NEW_YARK_NIGHT_R:
                return context.getResources().getString(R.string.stage_new_yark_night_r);

            case STAGE.JABRO_GROUND:
                return context.getResources().getString(R.string.stage_jaburo_ground);

            case STAGE.HIMALAYAS:
                return context.getResources().getString(R.string.stage_himalayas);

            case STAGE.HIMALAYAS_R:
                return context.getResources().getString(R.string.stage_himalayas_r);

            case STAGE.MINING_TOWN:
                return context.getResources().getString(R.string.stage_mining_town);

            case STAGE.MINING_TOWN_R:
                return context.getResources().getString(R.string.stage_mining_town_r);

            case STAGE.MINING_TOWN_NIGHT:
                return context.getResources().getString(R.string.stage_mining_town_night);

            case STAGE.MINING_TOWN_R_NIGHT:
                return context.getResources().getString(R.string.stage_mining_town_night_r);

            case STAGE.THE_ARCTIC_BASE:
                return context.getResources().getString(R.string.stage_the_arctic_base);

            case STAGE.ODESSA:
                return context.getResources().getString(R.string.stage_odessa);

            case STAGE.ODESSA_R:
                return context.getResources().getString(R.string.stage_odessa_r);

            case STAGE.AUSTRARIA:
                return context.getResources().getString(R.string.stage_austraria);

            case STAGE.BERUFAST:
                return context.getResources().getString(R.string.stage_berufast);

            case STAGE.TAKLAMAKAN_DESERT:
                return context.getResources().getString(R.string.stage_taklamakan_desert);

            case STAGE.JABRO:
                return context.getResources().getString(R.string.stage_jaburo);

            case STAGE.TORRINGTON:
                return context.getResources().getString(R.string.stage_torrington);

            case STAGE.TORRINGTON_R:
                return context.getResources().getString(R.string.stage_torrington_r);

            case STAGE.GREAT_CANYON:
                return context.getResources().getString(R.string.stage_great_canyon);

            case STAGE.TORRINGTON_BASE:
                return context.getResources().getString(R.string.stage_torrington_base);

            case STAGE.CALIFORNIA_BASE:
                return context.getResources().getString(R.string.stage_california_base);

            case STAGE.A_BAOA_QU:
                return context.getResources().getString(R.string.stage_a_baoa_qu);

            case STAGE.A_BAOA_QU_R:
                return context.getResources().getString(R.string.stage_a_baoa_qu_r);

            case STAGE.LUNA_II:
                return context.getResources().getString(R.string.stage_luna_two);

            case STAGE.ISRAND_EASE:
                return context.getResources().getString(R.string.stage_island_ease);

            case STAGE.SIDE_7:
                return context.getResources().getString(R.string.stage_side_7);

            case STAGE.RIBO_COLONY:
                return context.getResources().getString(R.string.stage_ribo_colony);

            case STAGE.RIBO_COLONY_AREA_B:
                return context.getResources().getString(R.string.stage_ribo_colony_area_b);

            case STAGE.JABURO_JUNGLE_AREA:
                return context.getResources().getString(R.string.stage_jaburo_jungle_area);

            case STAGE.GRANADA:
                return context.getResources().getString(R.string.stage_granada);

            default:
                return "";
        }

    }

    /**
     * カテゴリ名の取得
     * 
     * @param categoryCd
     * @return
     */
    public static String getCategoryNm(Context context, int categoryCd) {

        switch (categoryCd) {
            case CATEGORY.GRAPP:
                return context.getResources().getString(R.string.category_grapp);

            case CATEGORY.PROX:
                return context.getResources().getString(R.string.category_prox);

            case CATEGORY.SHOOT:
                return context.getResources().getString(R.string.category_shoot);

            case CATEGORY.CANNON:
                return context.getResources().getString(R.string.category_cannon);

            case CATEGORY.SNIPE:
                return context.getResources().getString(R.string.category_snip);

            default:
                return "";

        }

    }

    /**
     * 結果名の取得
     * 
     * @param context
     * @param resultCd
     * @return
     */
    public static String getResultNm(Context context, int resultCd) {
        
        switch (resultCd) {
            case RESULT.WIN:
                return context.getResources().getString(R.string.result_win);

            case RESULT.LOSE:
                return context.getResources().getString(R.string.result_lose);

            case RESULT.DRAW:
                return context.getResources().getString(R.string.result_draw);

            case RESULT.PERFECT_WIN:
                return context.getResources().getString(R.string.result_perfect_win);

            case RESULT.PERFECT_LOSE:
                return context.getResources().getString(R.string.result_perfect_lose);

            default:
                return "";
                
        }

    }

    /**
     * データベースのバージョン取得
     * 
     * @return
     */
    public static int getDatabaseVersion() {

        return DATABASE_VERSION;

    }

    /**
     * CSVファイル保存用のフォルダを取得
     * 
     * @param conn
     * @return
     */
    public static String getCurrentFolder(Context conn) {

        String sPath = Environment.getExternalStorageDirectory().toString() + "/Android/data/"
                + conn.getPackageName();

        return sPath;
    }

    /**
     * CSVファイルパスの取得
     * 
     * @param conn
     * @return
     */
    public static String getCsvFilePath(Context conn) {
        return getCurrentFolder(conn) + "/" + CSV_FILE_NAME;
    }

}
